<?php

$userPermissionCategories = new UserPermissionCategories();
$allCategories = $userPermissionCategories->getUserPermissionCategories();

?>

<?php include $this->getLayoutFile('block_top_messages'); ?>
<form class="form1" method="post" action="<?php echo $requestAction; ?>">

    <fieldset>
        <!-- <legend></legend> -->

        <div class="leftBlock">

            <div class="field">
                <label for="status"> 帳號啟用狀態 </label>
                <div class="show">
                    <select name="status">
                        <?php 
                            foreach( $user->getStatusList('status') as $name => $id ) {
                                if( $user->getStatus()==$id ) {
                                    $selected = ' selected="selected" ';
                                }
                                else {
                                    $selected = '';
                                }
                                echo "<option value='{$id}' {$selected}>". $user->trByName($name) ."</option>";
                            }

                        ?>
                    </select>
                </div>
                <div class="info"></div>
            </div>

            <div class="field">
                <label for="authType"> 認証身份 </label>
                <div class="show">
                    <?php
                        foreach( $user->getStatusList('authType') as $name => $id ) {
                            if( $user->getAuthType()==$id ) {
                                echo $user->trByName($name);
                                break;
                            }
                        }
                        /*
                        <select name="authType">
                        foreach( $user->getStatusList('authType') as $name => $id ) {
                            if( $user->getAuthType()==$id ) {
                                $selected = ' selected="selected" ';
                            }
                            else {
                                $selected = '';
                            }
                            echo "<option value='{$id}' {$selected} >". $user->trByName($name) ."</option>";
                        }
                        </select>
                        */
                    ?>
                </div>
            </div>

            <div class="field">
                <label for="email">Email</label>
                <div class="show">
                    <input type="text" name="email" value="<?php echo $user->getEmail(); ?>" size="30" />
                </div>
                <div class="info">
                    <?php echo $user->trByStatus('emailStatus', $user->getEmailStatus()); ?>
                </div>
                <?php $errorField="email"; include $this->getLayoutFile('block_fields'); ?>
            </div>

            <div class="field">
                <label for="categoriesList">權限列表</label>
                <div class="show">
                    <?php
                        foreach( $allCategories as $category ) {
                            $isMatch=false;
                            foreach( $user->getUserPermissionCategories() as $myCategory ) {
                                if( $category->getId() === $myCategory->getId() ) {
                                    $isMatch = true;
                                    break;
                                }
                            }
                            $matchString = '';
                            if( $isMatch ) {
                                $matchString = ' checked="checked" ';
                            }
                            echo '<input type="checkbox" class="checkbox" '. $matchString .' name="permissions[]" value="'. $category->getKeyName() .'" />';
                            if( 'plugin_'==substr($category->getKeyName(),0,7) ) {
                                echo '(外掛) ';
                            }
                            echo $category->getName();
                            echo '<br />';
                        }
                    ?>
                </div>
                <div class="info">
                </div>
                <?php $errorField="permissions"; include $this->getLayoutFile('block_fields'); ?>
            </div>

        </div>
        <div class="rightBlock">

            <div class="field">
                <label for="name"> 編號 </label>
                <div class="show">
                    <?php echo $user->getId(); ?>
                </div>
            </div>
            <div class="field">
                <label for="account"> 帳號 </label>
                <div class="show">
                    <?php echo $user->getAccount(); ?>
                </div>
            </div>
            <div class="field">
                <label for="create_date"> 建立日期 </label>
                <div class="show">
                    <?php echo $user->getCreateDateByFormat(); ?>
                </div>
            </div>
            <div class="field">
                <label for="update_date"> 修改日期 </label>
                <div class="show">
                    <?php echo $user->getUpdateDateByFormat(); ?>
                </div>
            </div>

        </div>
        <div class="submitBlock">

            <input class="submit" type="submit" value="更新" />

        </div>

    </fieldset>



</form>

